package com.marvels.approve.loan.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.marvels.approve.loan.dto.LoanSamplingDTO;
import com.marvels.approve.loan.service.ILoanSamplingService;
import com.marvels.common.dto.MarvelsResultDTO;
import com.marvels.common.exception.MarvelsBusinessException;
import com.marvels.common.exception.MarvelsErrorCode;
import com.marvels.common.utils.MarvelsLogUtil;

/**征信审计
 * 
 */
@RestController
@RequestMapping("approve/sampling/service")
public class LoanSamplingController {
	@Autowired
	private ILoanSamplingService loanSamplingService;
	/**查询审计相关内容
	 * @param loanSamplingDTO
	 * @return
	 */
	@RequestMapping("querysampling")
	public MarvelsResultDTO querysampling(@RequestBody(required=false) LoanSamplingDTO loanSamplingDTO) {
		try {
			LoanSamplingDTO resultLoanSampling = loanSamplingService.findSampling(loanSamplingDTO);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),resultLoanSampling);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>征信审计FAIL:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), e.getMessage(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>征信审计异常:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),"征信审计异常");
		}
	}
	
	/**保存征信审计信息
	 * @param loanSamplingDTO
	 * @return
	 */
	@RequestMapping("addsampling")
	public MarvelsResultDTO addsampling(@RequestBody(required=false) LoanSamplingDTO loanSamplingDTO) {
		try {
			LoanSamplingDTO resultLoanSampling = loanSamplingService.saveSampling(loanSamplingDTO);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),resultLoanSampling);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>征信审计保存FAIL:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), e.getMessage(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>征信审计保存:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),"征信审计保存");
		}
	}
	/**审计信息
	 * @param loanSamplingDTO
	 * @return
	 */
	@RequestMapping("complateSampling")
	public MarvelsResultDTO complateSampling(@RequestBody(required=false) LoanSamplingDTO loanSamplingDTO) {
		try {
			LoanSamplingDTO resultLoanSampling = loanSamplingService.complateSampling(loanSamplingDTO);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),resultLoanSampling);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>征信审计完成任务FAIL:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), e.getMessage(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>征信审计完成任务:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),"征信审计完成任务");
		}
	}
}
